#include "memory.h"


/**
 * Allocates an unitialized memory-block of "size" bytes and returns a pointer to it.
 * @param size the size of the memory-block to allocate
 * @return Returns a pointer to the allocated memory-block, or NULL if "size" is 0 or if an error occured
 * @note The allocated block will have to be freed by using memoryFree() when no longer needed.
 */
void* memoryAlloc(size_t size) {
  return malloc(size);
}


/**
 * Allocates an unitialized memory-block of "size" bytes and returns a pointer to it. The allocated block
 * will be managed by the garbage-collector and will be automatically freed when no longer referenced.
 * @param size the size of the memory-block to allocate
 * @return Returns a pointer to the allocated memory-block, or NULL if "size" is 0 or if an error occured
 */
void* memoryAllocGC(size_t size) {
  //TODO: implement a garbage-collector...
  return malloc(size);
}


/**
 * Changes the size of the given memory-block that has been allocated with memoryAlloc().
 * The contents will remain unchanged (but may be truncated if "size" is less than the previous size).
 * @param ptr a pointer to the memory-block to resize (if NULL, memoryRealloc() is equivalent to memoryAlloc())
 * @param size the new size of the memory-block (if 0, memoryRealloc() is equivalent to memoryFree())
 * @return Returns a pointer to the resized memory-block, or NULL if "size" is 0 or if an error occured
 */
void* memoryRealloc(void* ptr, size_t size) {
  return realloc(ptr, size);
}


/**
 * Frees the given memory-block that has been allocated with memoryAlloc().
 * @param ptr a pointer to the memory-block to free. If NULL, nothing occurs
 */
void memoryFree(void* ptr) {
  free(ptr);
}
